package dao;
import model.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    /**
     * 登陆验证
     * @param connection
     * @param user
     * @return
     * @throws SQLException
     */
    public User login(Connection connection, User user) throws SQLException {
        User resultuser=null;
        String sql="select* from t_user where userName=? and password=?";
        PreparedStatement pstmt= connection.prepareStatement(sql);
        pstmt.setString(1,user.getUserName());
        pstmt.setString(2,user.getPassword());
        ResultSet rs=pstmt.executeQuery();
        while (rs.next()){
            resultuser=new User();
            resultuser.setId(rs.getInt("id"));
            resultuser.setUserName(rs.getString("userName"));
            resultuser.setPassword(rs.getString("password"));
        }
        return resultuser;
    }
}
